# Base entity class
from pyston import *

class Entity:
    
    # Constructor
    def __init__(self):
        # Entity naming
        self.type = "unknown"
        self.name = "noname"
        
        # Update rate in seconds
        self.updateInterval = 1
        self.currentTime = 0
        
        # Callback constants
        self.uses_update = True
        self.uses_create = True
        self.uses_destroy = True
        self.uses_activate = True
        self.uses_deactivate = True
        
        # Resource manager
        self.resourceManager = None
        
        # Drawing
        self.displayMode = dm_none
        self.requiresRedraw = False
        
        # Creation callback
        self.create()
        
    def __del__(self):
        self.destroy()
        
    def setName(self, newName):
        self.name = newName
        
    def setResourceManager(self, rsMan):
        self.resourceManager = rsMan
        
    def stepFrame(self, timeSinceLastFrame):
        # Check whether the entity should act on this frame
        self.currentTime += timeSinceLastFrame
        
        if self.currentTime > self.updateInterval:
            self.currentTime = 0
            self.update()
            
    def setUpdateInterval(self, newUpdateInterval):
        self.updateInterval = newUpdateInterval
        
    def getUpdateInterval(self):
        return self.updateInterval
    
    def getCurrentTime(self):
        return self.currentTime
    
    def getDisplayMode(self):
        return self.displayMode
    
    # Optionally overridden methods        
    def update(self):
        if self.uses_update == True:
            debug_out(self.type + " Entity \"" + self.name + "\" has not overriden its update() method.")
            
    def activate(self):
        if self.uses_activate == True:
            debug_out(self.type + " Entity \"" + self.name + "\" has not overriden its activate() method.")
    
    def deactivate(self):
        if self.uses_deactivate == True:
            debug_out(self.type + " Entity \"" + self.name + "\" has not overriden its deactivate() method.")
        
    def create(self):
        if self.uses_create == True:
            debug_out(self.type + " Entity \"" + self.name + "\" has not overriden its create() method.")
        
    def destroy(self):
        if self.uses_destroy == True:
            debug_out(self.type + " Entity \"" + self.name + "\" has not overriden its destroy() method.")